package com.itmuch.demoprovider.user;

import com.google.common.collect.Lists;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController
public class UserController {
    @PostMapping("login")
    public UserLoginDTO login(@RequestBody UserLoginDTO userLoginDTO) {
        if ("zhangsan".equals(userLoginDTO.getUsername())) {
            return userLoginDTO;
        }
        throw new IllegalArgumentException("username invalid.");
    }

    @GetMapping("/getUserInfo")
    public List<UserSearchDTO> getUserInfo(@RequestParam String username, @RequestParam Short gender) {
        List<UserSearchDTO> nv = Stream.of(0, 1, 2)
            .map(i -> {
                return new UserSearchDTO(
                    username + i,
                    gender,
                    (short) (i + 28)
                );
            }).collect(Collectors.toList());
        return Lists.newArrayList(nv);
    }
}
